import { Nodes } from '@knno/dom';
import { Checkbox as UICheckbox, CheckState } from '../components/checkbox/checkbox';
import { JSXProps } from '@knno/dom/jsx';
import { AttrCheck, isBool, isObject, isStr, jsxBuild } from './utils';
import { FacadeIcons } from '../components/checkbox/checkable';

export { UICheckbox };

interface CheckboxProps extends JSXProps<UICheckbox> {
	checked?: CheckState;
	text?: string;
	value?: unknown;
	disabled?: boolean;
	facadeIcons?: FacadeIcons;
}

const ATTRS: AttrCheck = {
	checked: (v: unknown) => v === 'half' || isBool(v),
	text: isStr,
	disabled: isBool,
	facadeIcons: isObject,
};

export function Checkbox(props: CheckboxProps, children: Nodes[]): UICheckbox {
	return jsxBuild(new UICheckbox(), props, children, ATTRS);
}
